package cn.cjxy.javaweb.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author huangjie
 * @date 2025/9/29
 */
@WebServlet("/servlet2")//访问地址
public class MyServletAnnotation extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应格式
        resp.setContentType("text/html;charset=utf-8");

        //得到写对象
        PrintWriter writer = resp.getWriter();
        writer.println("<h1>hello servlet</h1>");
    }
}
